<?php

namespace App\Http\Requests\Api;

class MemberCardsRequest extends FormRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case 'GET':
                {
                    return [
                        'id' => ['required', 'exists:shop_user,id'],
                    ];
                }
            case 'POST':
                {
                    return [
                        'type' => ['required', 'in:1,2'],
                        'name' => ['required', 'max:12', 'unique:member_cards,name'],
                        'price' => ['required', 'numeric'],
                        'market_price' => ['required', 'numeric'],
                        'days' => ['required', 'integer'],
                        'cover_url' => ['required', 'string'],
                        'sort' => ['sometimes', 'required', 'integer'],
                    ];
                }
            default:
                {
                    return [

                    ];
                }
        }
    }

    public function messages()
    {
        return [
            'type.required'=>'类型必须填写',
            'type.in'=>'类型值非法',
            'name.required' => '名称不能为空',
            'name.unique' => '名称已经存在',
            'name.max' => '名称最大长度为12个字符',
            'price.required' => '价格不能为空',
            'price.numeric' => '价格值必须是数字',
            'market_price.required' => '市场价不能为空',
            'market_price.numeric' => '市场价值必须是数字',
            'days.required' => '有效期不能为空',
            'days.integer' => '有效期必须是整数',
            'cover_url.required' => '封面图不能为空',
            'sort.required' => '排序不能为空',
            'sort.integer' => '排序只能是整数',
        ];
    }
}
